<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>debug_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_debug_debug_test.js.html">debug_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.debugTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.debugTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.debug&#39;);
<a name="line19"></a>goog.require(&#39;goog.structs.Set&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>function testMakeWhitespaceVisible() {
<a name="line23"></a>  assertEquals(
<a name="line24"></a>      &#39;Hello[_][_]World![r][n]\n&#39; +
<a name="line25"></a>      &#39;[r][n]\n&#39; +
<a name="line26"></a>      &#39;[f][f]I[_]am[t][t]here![r][n]\n&#39;,
<a name="line27"></a>      goog.debug.makeWhitespaceVisible(
<a name="line28"></a>          &#39;Hello  World!\r\n\r\n\f\fI am\t\there!\r\n&#39;));
<a name="line29"></a>}
<a name="line30"></a>
<a name="line31"></a>function testGetFunctionName() {
<a name="line32"></a>  // Trivial resolver that matches just a few names: a static function, a
<a name="line33"></a>  // constructor, and a member function.
<a name="line34"></a>  var resolver = function(f) {
<a name="line35"></a>    if (f === goog.debug.getFunctionName) {
<a name="line36"></a>      return &#39;goog.debug.getFunctionName&#39;;
<a name="line37"></a>    } else if (f === goog.structs.Set) {
<a name="line38"></a>      return &#39;goog.structs.Set&#39;;
<a name="line39"></a>    } else if (f === goog.structs.Set.prototype.getCount) {
<a name="line40"></a>      return &#39;goog.structs.Set.getCount&#39;;
<a name="line41"></a>    } else {
<a name="line42"></a>      return null;
<a name="line43"></a>    }
<a name="line44"></a>  };
<a name="line45"></a>  goog.debug.setFunctionResolver(resolver);
<a name="line46"></a>
<a name="line47"></a>  assertEquals(
<a name="line48"></a>      &#39;goog.debug.getFunctionName&#39;,
<a name="line49"></a>      goog.debug.getFunctionName(goog.debug.getFunctionName));
<a name="line50"></a>  assertEquals(
<a name="line51"></a>      &#39;goog.structs.Set&#39;,
<a name="line52"></a>      goog.debug.getFunctionName(goog.structs.Set));
<a name="line53"></a>  var set = new goog.structs.Set();
<a name="line54"></a>  assertEquals(
<a name="line55"></a>      &#39;goog.structs.Set.getCount&#39;,
<a name="line56"></a>      goog.debug.getFunctionName(set.getCount));
<a name="line57"></a>
<a name="line58"></a>  // This function is matched by the fallback heuristic.
<a name="line59"></a>  assertEquals(
<a name="line60"></a>      &#39;testGetFunctionName&#39;,
<a name="line61"></a>      goog.debug.getFunctionName(testGetFunctionName));
<a name="line62"></a>
<a name="line63"></a>  goog.debug.setFunctionResolver(null);
<a name="line64"></a>}
<a name="line65"></a>
<a name="line66"></a>
<a name="line67"></a>/**
<a name="line68"></a> * Asserts that a substring can be found in a specified text string.
<a name="line69"></a> *
<a name="line70"></a> * @param {string} substring The substring to search for.
<a name="line71"></a> * @param {string} text The text string to search within.
<a name="line72"></a> */
<a name="line73"></a>function assertContainsSubstring(substring, text) {
<a name="line74"></a>  assertNotEquals(&#39;Could not find &quot;&#39; + substring + &#39;&quot; in &quot;&#39; + text + &#39;&quot;&#39;,
<a name="line75"></a>      -1, text.search(substring));
<a name="line76"></a>}
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>function testDeepExpose() {
<a name="line80"></a>  var a = {};
<a name="line81"></a>  var b = {};
<a name="line82"></a>  a.ancestor = a;
<a name="line83"></a>  a.otherObject = b;
<a name="line84"></a>  a.otherObjectAgain = b;
<a name="line85"></a>
<a name="line86"></a>  var deepExpose = goog.debug.deepExpose(a);
<a name="line87"></a>
<a name="line88"></a>  assertContainsSubstring(&#39;ancestor = ... reference loop detected ...&#39;,
<a name="line89"></a>                          deepExpose);
<a name="line90"></a>
<a name="line91"></a>  assertContainsSubstring(&#39;otherObjectAgain = {&#39;, deepExpose);
<a name="line92"></a>}
</pre>


</body>
</html>
